package cn.mabach.goods.service.impl;


import cn.mabach.DTO.PageUtils;
import cn.mabach.DTO.RS;
import cn.mabach.goods.dao.SpecDao;
import cn.mabach.goods.entity.SpecEntity;
import cn.mabach.goods.service.SpecService;
import cn.mabach.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class SpecServiceImpl extends ServiceImpl<SpecDao, SpecEntity> implements SpecService {

    @Override
    public RS<PageUtils> queryPage(@RequestParam Map<String, Object> params) {
        IPage<SpecEntity> page = this.page(
                new Query<SpecEntity>().getPage(params),
                new QueryWrapper<SpecEntity>()
        );
        if (page==null){
            return RS.error();
        }
        return RS.ok(new PageUtils(page));
    }





    @Override
    public RS<SpecEntity> getByIdE(@RequestParam("id") Integer id) {
            SpecEntity res = this.getById(id);
        if (res==null){
            return RS.error();
        }
        return RS.ok(res);
    }

    @Override
    public RS saveE(@RequestBody  SpecEntity entity) {
        boolean b = this.save(entity);
        if (!b){
            return RS.error();
        }
        return RS.ok();
    }

    @Override
    public RS updateByIdE(@RequestBody SpecEntity entity) {
        boolean b = this.updateById(entity);
        if (!b){
            return RS.error();
        }
        return RS.ok();
    }

    @Override
    public RS removeByIdsE(@RequestBody List<Integer> ids) {
        boolean b = this.removeByIds(ids);
        if (!b){
            return RS.error();
        }
        return RS.ok();
    }

}